<?php
class Admin {
	function __construct(){
		
	}
	
	function setting($data){
		global $conf;
		$db = new db($conf);
		$webstate = isset($data['webstate'])?intval($data['webstate']):1;
		$webname = isset($data['webname'])?trim($data['webname']):1;
		$content = isset($data['content'])?trim($data['content']):1;
		if($webstate==0){
			$content = $content?$content:"系统升级中 请耐心等待";
		}		
		$field = array("webstate"=>$webstate,"webname"=>$webname,"content"=>$content);
		$db->where("reg=1")->update("sc_system",$field);
		$field1 = array_diff_key($_POST,$field);
		
		$db->where("Id=1")->update("sc_set",$field1);
		success("修改成功");
	}

	function xgpassword($data){
		global $conf;
		$db = new db($conf);
		$username = $_SESSION['a']['auname'];
		$oldpass = isset($data['t0'])?trim($data['t0']):"";
		$newpass = isset($data['t1'])?trim($data['t1']):"";
		$newpass1 = isset($data['t2'])?trim($data['t2']):"";
		if(empty($oldpass)){$str = array("0","请输入原密码");echo json_encode($str);exit;}
		if(empty($newpass)){$str = array("0","请输入新密码");echo json_encode($str);exit;}
		if(empty($newpass1)){$str = array("0","请再次输入新密码");echo json_encode($str);exit;}
		if(strlen($newpass)<6){$str = array("0","请输入6位以上字母+数字密码");echo json_encode($str);exit;}
		if((strlen($newpass) != strlen($newpass1)) || $newpass != $newpass1){$str = array("0","重复输入密码不一致");echo json_encode($str);exit;}
		$result = $db->field(array("auname","apwd"))->where(array("auname"=>"'".$username."'","apwd"=>"'".MD5($oldpass)."'"))->select("sc_admin");
		if($result){
			if(($result[0]['auname']!=$username) || strlen($result[0]['auname'])!=strlen($username)){
				$str = array(0,"修改密码失败");
				echo json_encode($str);
			}
			else{
				$field = array("apwd"=>MD5($newpass));
				$r1 = $db->where(array("auname"=>"'".$result[0]['auname']."'"))->update("sc_admin",$field);
				if(!$r1){
					$str = array(0,"修改密码失败");
					echo json_encode($str);
				}
				else{
					$str = array(1,"修改成功");
					echo json_encode($str);
				}
			}
		}
		else{
			$str = array(0,"修改密码失败");
			echo json_encode($str);
		}
	}
	
	function xgpassword1($data){
		global $conf;
		$db = new db($conf);
		$username = $_SESSION['a']['auname'];
		$oldpass = isset($data['t0'])?trim($data['t0']):"";
		$newpass = isset($data['t1'])?trim($data['t1']):"";
		$newpass1 = isset($data['t2'])?trim($data['t2']):"";
		if(empty($oldpass)){error("请输入原支付密码");}
		if(empty($newpass)){error("请输入新支付密码");}
		if(empty($newpass1)){error("请再次输入新支付密码");}
		if(strlen($newpass)<6){error("请输入6位以上字母+数字密码");}
		if((strlen($newpass) != strlen($newpass1)) || $newpass != $newpass1){error("重复输入密码不一致");}
		$result = $db->field(array("auname","apwd2"))->where(array("auname"=>"'".$username."'","apwd2"=>"'".MD5($oldpass)."'"))->select("sc_admin");
		if($result){
			if(($result[0]['auname']!=$username) || strlen($result[0]['auname'])!=strlen($username)){
				error("修改密码失败");				
			}
			else{
				$field = array("apwd2"=>MD5($newpass));
				$r1 = $db->where(array("auname"=>"'".$result[0]['auname']."'"))->update("sc_admin",$field);
				if(!$r1){error("修改密码失败");}
				else{success("修改成功");}
			}
		}
		else{error("原支付密码错误");}
	}
}